cmake_minimum_required(VERSION 3.10)
project(screencap)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)

include_directories(./screencap)

set(SRC
    ./screencap/readthread.cpp
    # ./screencap/tcpsocket.cpp
    ./screencap/videocodec.cpp
    ./screencap/videodecode.cpp
)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SRC
    ./screencap/readthread.cpp
    ./screencap/videodecode.cpp
    ./screencap/videocodec.cpp
)

add_executable(screencap
    main.cpp
    ${SRC}
    # widget.cpp
    # widget.h
    # widget.ui
)

find_package(PkgConfig)
if (PkgConfig_FOUND)
    pkg_check_modules(FFmpeg libavformat>=58 libavcodec>=58 libavutil>=56 libswscale>=5)
    if (FFmpeg_FOUND)
        target_link_options(${PROJECT_NAME} PRIVATE ${FFmpeg_LDFLAGS})
        target_compile_options(${PROJECT_NAME} PRIVATE ${FFmpeg_CFLAGS})
        set(EXTERNAL_LIBS_FFMPEG ${FFmpeg_LIBRARIES})
    endif ()
endif ()

target_link_libraries(screencap PRIVATE ${EXTERNAL_LIBS_FFMPEG} avdevice)

target_link_libraries(screencap PRIVATE
    Qt5::Core
    Qt5::Gui
    Qt5::Widgets
)

include_directories(${CMAKE_SOURCE_DIR}/screencap)

# Define program version
set(VERSION 1.0.3)
add_definitions(-DAPP_VERSION=\"${VERSION}\")

# Set output directory based on architecture
# if(CMAKE_SIZEOF_VOID_P EQUAL 4)
#     set(DESTDIR ${CMAKE_CURRENT_SOURCE_DIR}/../bin)
# else()
#     set(DESTDIR ${CMAKE_CURRENT_SOURCE_DIR}/../bin64)
# endif()
